#include <iostream>

using namespace std;

const int N = 300;

int n;
char root;
char l[N], r[N];

void dfs(char root)
{
	if(root == '*') return;

	cout << root;
	dfs(l[root]);
	dfs(r[root]);
}

int main()
{
	cin >> n;
	//处理根节点
	cin >> root;
	cin >> l[root] >> r[root];

	for(int i = 2; i <= n; i++)
	{
		char t; cin >> t;
		cin >> l[t] >> r[t];
	}
	//前序遍历
	dfs(root);

	return 0;
}


